{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>

<form action="" id="img-form" method="post" enctype="multipart/form-data" >
    {% csrf_token %}
    <button onclick='abc()' >时</button>
    <img src="{{MEDIA_URL}}{{media.image}}" alt="">
    <input type="file" name="img" id="img">
    <input type="text" name='description' placeholder='description'>
    <input type="submit" onclick="upload_img" value="提交">
</form>

<script type="text/javascript" src="{% static 'js/jquery-3.7.1.min.js' %}"></script>
<script>
    var data={{test|safe}};
    function abc(){
        document.write(data.length)
        for (let i=0;i<data.length;i++){
            document.write(data[i].fields.name)
        }
}
</script>
{% comment %} <script type="text/javascript">
    function upload_img() {
        let formData = new FormData($("#img-form")[0]);
        $.ajax({
            url: "/addgoods/", //请求路径
            type: 'POST', // 请求类型
            data: formData, // 请求数据
            dataType: "JSON", // 返回数据格式
            contentType: false, //表示不处理数据
            processData: false,
            cache: false,
            success: function (data) {
                if (data === 1) { 
                    alert("上传成功");
                }else if (data === 0) {
                    alert("上传失败");
                }
            },
            error: function (data) {
                console.log(data);
            }
        });
    }
</script> {% endcomment %}
</body>
</html>